/*
 * Created on 08/23/2011 - 04:35 PM
 */
package sembr.geometry.shapes;

import importadorDXF.DxfPOLYLINE;
import importadorDXF.DxfVERTEX;
import sembr.geometry.interfacing.ShapeBase;

/**
 *
 * @author Adriano
 */
public class PolylineCollector extends ShapeBase<DxfPOLYLINE>
{ 
    public PolylineCollector() 
    {}
    
    public int getTotalNrOfVertices()
    {
        int nrOfVertices = 0;
        
        for (int i = 0; i < this.length(); i++)
        {
            nrOfVertices += this.getNrOfVertexAt(i);
        }
        
        return nrOfVertices;        
    }
    
    public int getNrOfVertexAt(int index)       
    {
        int nrOfVertex = 0;
        
        DxfPOLYLINE polyline = getCurrentElement(index);
        
        if (polyline.vertexFollowing())
            nrOfVertex = polyline.getVertices().getNrOfEntities();
        
        return nrOfVertex;
    }  
    
    public double[][] getVerticesCoordenatesAt(int index)
    {
        int nrOfVertex = getNrOfVertexAt(index);
        
        // coordenates in 3D
        double[][] points = new double[nrOfVertex][3];
        
        for (int i = 0; i < nrOfVertex; i++)
        {
            DxfVERTEX vertex = (DxfVERTEX)(getCurrentElement(index)).getVertices().getEntity(i);
                      
            points[i][0] = vertex.getPosition().x;
            points[i][1] = vertex.getPosition().y;
            points[i][2] = vertex.getPosition().z;           
        }
        
        return points;
    }   
}
